namespace Maple.Branch.Identity
{
    using Microsoft.Extensions.DependencyInjection;
    using Permissions;
    using TestDatas;
    using Volo.Abp;
    using Volo.Abp.Modularity;
    using Volo.Abp.Threading;

    [DependsOn(typeof(IdentityEfCoreTestModule),
        typeof(IdentityPermissionProviderModule),
        typeof(PermissionsDomainModule)
        )]
    public class IdentityDomainTestModule : AbpModule
    {
        public override void OnApplicationInitialization(ApplicationInitializationContext context)
        {
            SeedTestData(context);
        }

        private static void SeedTestData(ApplicationInitializationContext context)
        {
            using var scope = context.ServiceProvider.CreateScope();

            AsyncHelper.RunSync(async () =>
            {
                await scope.ServiceProvider
                    .GetRequiredService<TestPermissionDataBuilder>()
                    .SeedAsync();
            });
        }
    }
}
